#![allow(unused)]

#[cfg(test)]
pub mod test_enum {
    use super::denum;

    #[test]
    fn tenum() {
        denum();
    }
}

pub fn denum() {
    println!(" --------- enum ------------- ");
    /* 枚举
     */
    let v4 = IPKind::V4;
    let v6 = IPKind::V6;

    let localhost = IPAddress {
        kind: IPKind::V4,
        addr: String::from("127.0.0.1"),
    };

    let local127 = IPAddr::V4(127, 0, 0, 1);
    // 枚举定义函数 也用impl
    local127.p();

    let q = Message::Quit;
    let m = Message::Move { x: 12, y: 61 };
    let w = Message::Write(String::from("enum writr"));
    let c = Message::Color(128, 128, 128, 128);
}

pub enum Message {
    Quit,
    Move {x: i32, y: i32},
    Write(String),
    Color(u8, u8, u8, u8),
    IP(IPKind),
}


#[derive(Debug)]
pub enum IPKind {
    V4,
    V6,
}

enum IPAddr {
    V4(u8, u8, u8, u8),
    V6(String)
}

impl IPAddr {
    fn p(&self) {
    }
}

struct IPAddress {
    kind: IPKind,
    addr: String,
}



pub struct Color(pub u8, pub u8, pub u8, pub u8);
pub struct Point(pub f64, pub f64, pub f64, pub f64);

#[derive(Debug)]
pub struct User {
    pub id: u64,
    pub name: String,
    pub age: u16,
    pub sex: u8,
    pub email: String
}

// 定义方法
impl User {
    pub fn is_girl(&self) -> bool {
        self.sex == 0
    }

    // 第一个参数不是 self， 通常用于构造方法
    pub fn get_u16() -> u16 {
        16
    }
}

impl User {
    // 第一个参数不是 self， 通常用于构造方法
    pub fn smill_girl() -> User {
        User {
            id: 12,
            name: String::from("small girl"),
            age: 16,
            sex: 0,
            email: String::from("sg@61linux.com"),
        }
    }
}
